package com.yololabelmaker;

import java.awt.*;

public class LabelRect {
    private int x;
    private int y;
    private int width;
    private int height;
    private String className;
    private int classId;
    
    public LabelRect() {
        this.x = 0;
        this.y = 0;
        this.width = 0;
        this.height = 0;
        this.className = "";
        this.classId = 0;
    }
    
    public void setRect(Point startPoint, Point endPoint) {
        this.x = Math.min(startPoint.x, endPoint.x);
        this.y = Math.min(startPoint.y, endPoint.y);
        this.width = Math.abs(endPoint.x - startPoint.x);
        this.height = Math.abs(endPoint.y - startPoint.y);
    }
    
    public int getX() {
        return x;
    }
    
    public void setX(int x) {
        this.x = x;
    }
    
    public int getY() {
        return y;
    }
    
    public void setY(int y) {
        this.y = y;
    }
    
    public int getWidth() {
        return width;
    }
    
    public void setWidth(int width) {
        this.width = width;
    }
    
    public int getHeight() {
        return height;
    }
    
    public void setHeight(int height) {
        this.height = height;
    }
    
    public String getClassName() {
        return className;
    }
    
    public void setClassName(String className) {
        this.className = className;
    }
    
    public int getClassId() {
        return classId;
    }
    
    public void setClassId(int classId) {
        this.classId = classId;
    }
    
    // 保存原始的YOLO坐标比例信息
     private double yoloCenterX;
     private double yoloCenterY;
     private double yoloWidth;
     private double yoloHeight;
     
     public void setUserData(double centerX, double centerY, double width, double height) {
         this.yoloCenterX = centerX;
         this.yoloCenterY = centerY;
         this.yoloWidth = width;
         this.yoloHeight = height;
     }
     
     // 获取保存的YOLO坐标比例信息
     public double getYoloCenterX() {
         return yoloCenterX;
     }
     
     public double getYoloCenterY() {
         return yoloCenterY;
     }
     
     public double getYoloWidth() {
         return yoloWidth;
     }
     
     public double getYoloHeight() {
         return yoloHeight;
     }
    
    // 获取YOLO格式的中心点x坐标（相对于图片宽度的比例）
    public double getYOLOCenterX(double imageWidth) {
        return (x + width / 2.0) / imageWidth;
    }
    
    // 获取YOLO格式的中心点y坐标（相对于图片高度的比例）
    public double getYOLOCenterY(double imageHeight) {
        return (y + height / 2.0) / imageHeight;
    }
    
    // 获取YOLO格式的宽度（相对于图片宽度的比例）
    public double getYOLOWidth(double imageWidth) {
        return (double) width / imageWidth;
    }
    
    // 获取YOLO格式的高度（相对于图片高度的比例）
    public double getYOLOHeight(double imageHeight) {
        return (double) height / imageHeight;
    }
}